import * as ACTION_TYPS from './constant';
import { createReducer } from '@/store/utils';

let initState = {
    loading: false, // loading
    switchSearch: false,//默认待寄送筛选条件
    cancelExpressSuccess: false,
    chgwaybillNoBoolean: false,
    logisticsRequestParam: {
        "batchNo": "",
        "bussinessNo": "",
        "bussinessType": "",
        "invoiceCode": "",
        "invoiceNo": "",
        "invoiceType": "",
        "receiverCompanyName": "",
        "receiverName": "",
        "receiverTel": "",
        "senderCompanyName": "",
        "senderName": "",
        "senderTel": "",
        "waybillNo": "",
        "createTimeScope": {
            "first": "",
            "second": ""
        },
        "amountWithTaxScope": {
            "first": "",
            "second": ""
        },
        "paperDrewDateScope": {
            "first": "",
            "second": ""
        },
        "senderTimeScope": {
            "first": "",
            "second": ""
        },
    },//筛选器对象
    orderParam: { orderNum: 2 }, // 排序方式,默认创建时间降序
    countWait: { waitSend: 0, },
    countParcel: { sendingNum: 0, exceptionNum: 0, sendedNum: 0 },
    toSendList: [],//待寄件-数据列表
    parcel: [],//包裹总数
    parcelDetail: [],//包裹详情
    cancelSendGoods: {},//无需寄送
    sendedList: [],//寄件列表
    sendTypeList: [],//（分开、合并）列表
    submitParcels: [],//提交包裹信息
    express: [],//物流
    parcelLgtResult: {},//快递信息
    userReSource: [],//用户资源吗
    //-----------------------------------------------------------------------------------------------------

};

function loading(state, action) {
    return Object.assign({}, state, {
        loading: action.loading
    });
}
function switchSearch(state, action) {//切换筛选开关
    return Object.assign({}, state, {
        switchSearch: action.boolean
    });
}
function getDeleteParcelId(state, action) {//删除包裹
    return Object.assign({}, state, {
        sendTypeList: action.newSendTypeList
    });
}

function resetState(state, action) {//重置状态
    return Object.assign({}, state, {
        cancelSendGoods: action.cancelSendGoods
    });
}
function cancelExpress(state, action) {//取消快递
    return Object.assign({}, state, {
        cancelExpressSuccess: action.cancelExpressSuccess,
        chgwaybillNoBoolean: action.chgwaybillNoBoolean,
    });
}

function getLogisticsRequestParam(state, action) {//筛选器条件
    return Object.assign({}, state, {
        logisticsRequestParam: action.logisticsRequestParam
    });
}

function getOrderParam(state, action) {//排序方式
    return Object.assign({}, state, {
        orderParam: action.orderParam
    });
}

function getCountWait(state, action) {//待寄送 总数
    return Object.assign({}, state, {
        countWait: { waitSend: action.countWait && action.countWait.waitSendNum || '0' }
    })
}

function getCountParcel(state, action) {//寄送中，异常，已签收
    return Object.assign({}, state, {
        countParcel: {
            sendingNum: action.countParcel && action.countParcel.sendingNum || '0',
            exceptionNum: action.countParcel && action.countParcel.exceptionNum || '0',
            sendedNum: action.countParcel && action.countParcel.sendedNum || '0',
        }
    })
}

function getToSendList(state, action) {//待寄件列表
    return Object.assign({}, state, {
        toSendList: action.toSendList
    })
}

function getParcel(state, action) {//寄送中，异常，已签收 包裹总数
    return Object.assign({}, state, {
        parcel: action.parcel
    })
}

function getParcelDetailById(state, action) {// 包裹详情
    return Object.assign({}, state, {
        parcelDetail: action.parcelDetail
    })
}

function getCancelSendGoods(state, action) {// 无需寄送
    return Object.assign({}, state, {
        cancelSendGoods: action.cancelSendGoods
    })
}

function getSended(state, action) {//寄件
    return Object.assign({}, state, {
        sendedList: action.sended
    })
}

function getSendtype(state, action) {//(分开、合并)寄送
    // console.log(`merge or part=>`, action)
    return Object.assign({}, state, {
        sendTypeList: action.sendtype
    })
}

function getSubmitParcels(state, action) {//提交包裹
    return Object.assign({}, state, {
        submitParcels: action.submitParcels
    })
}

function getExpress(state, action) {//获取物流
    return Object.assign({}, state, {
        express: action.express
    })
}

function getParcelLgtResult(state, action) {//获取快递信息
    return Object.assign({}, state, {
        parcelLgtResult: action.parcelLgtResult
    })
}

function getUsersourceapiUrls(state, action) {//获取用户资源吗
    return Object.assign({}, state, {
        userReSource: action.userReSource
    })
}


// ---------------------------------------------------------------------------------------------------test
const Reducer = createReducer(initState, {
    [ACTION_TYPS.LOADING]: loading,
    [ACTION_TYPS.SEARCHFILTER]: switchSearch,//切换查询
    [ACTION_TYPS.DELETEPARCELID]: getDeleteParcelId,//删除包裹
    [ACTION_TYPS.RESETSTATE]: resetState,//重置状态
    [ACTION_TYPS.CANCENEXPRESSSUCCESS]: cancelExpress,//取消快递
    [ACTION_TYPS.LOGISTICSREQUESTPARAM]: getLogisticsRequestParam,//筛选条件
    [ACTION_TYPS.COUNTWAIT]: getCountWait,//待寄送 总数
    [ACTION_TYPS.TOSENDLIST]: getToSendList,// 待寄送列表
    [ACTION_TYPS.COUNTPARCEL]: getCountParcel,//寄送中，异常，已签收PARCEL
    [ACTION_TYPS.PARCEL]: getParcel,//寄送中，异常，已签收 包裹总数
    [ACTION_TYPS.PARCELDETAIL]: getParcelDetailById,//包裹详情
    [ACTION_TYPS.CANCELSENDGOODS]: getCancelSendGoods,//无需寄件
    [ACTION_TYPS.SENDED]: getSended,//寄件
    [ACTION_TYPS.PARTSENDPARCEL]: getSendtype,//(分开、合并)寄送
    [ACTION_TYPS.MERGESENDPARCEL]: getSendtype,//(分开、合并)寄送
    [ACTION_TYPS.SUBMITPARCELS]: getSubmitParcels,//提交包裹
    [ACTION_TYPS.ORDERPARAM]: getOrderParam,//排序方式
    [ACTION_TYPS.EXPRESS]: getExpress,//物流
    [ACTION_TYPS.PARCELLGTRESULT]: getParcelLgtResult,//快递信息
    [ACTION_TYPS.USERRESOURCE]: getUsersourceapiUrls,//获取用户资源吗

    //---------------------------------------------------------------
});

export default Reducer;
